﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;
using System.Reflection;
using System.Windows;
using System.Drawing;

namespace pklib.Manip {
	public class RegexConverter : IValueConverter {
		public String ItemValuePath { get; set; }

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			String s = value as String;
			if (s == null) {
				MethodInfo mi = value.GetType().GetMethod("ToString", Type.EmptyTypes);
				if(mi != null)
					s = (String)mi.Invoke(value,null);
			}
			return Patterns.ResolvePattern(s, (parameter as String).Split(',')[0]);
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
			String s = value as String;

			return Patterns.ResolvePattern(s, (parameter as String).Split(',')[1]);
		}
	}


}
